﻿@model QuanLySanXuat.Models.StorageDetailFormModels
@{
    ViewBag.Title = "Kết thúc sản xuất";
}
<link href="@Url.Content("~/ContentTMT/dateui.css")" rel="stylesheet" />
<script type="text/javascript">
    $(document).ready(function () {
        $(function () {
            $("#DateOut").datepicker();
            $("#DateOut").datepicker("option", "dateFormat", "dd/mm/yy");
        });
    });
</script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#CheckValid').bootstrapValidator({
            message: 'This value is not valid',
            excluded: [':disabled'],
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                BillNumber: {
                    validators: {
                        notEmpty: {
                            message: 'Mã không để trống'
                        }
                    }
                },
                OrderSummaryID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn lệnh kết thúc'
                        }
                    }
                },
                Employee1ID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn người duyệt'
                        }
                    }
                },
                Employee2ID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn người giao'
                        }
                    }
                },
                Employee3ID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn người nhận'
                        }
                    }
                },
                WarehouseID: {
                    validators: {
                        notEmpty: {
                            message: 'Phải chọn kho'
                        }
                    }
                },
            }
        }).on('success.form.bv', function (e) {
            // Prevent form submission
            e.preventDefault();

            // Get the form instance
            var $form = $(e.target);

            // Get the BootstrapValidator instance
            var bv = $form.data('bootstrapValidator');
            $("#DateOut").datepicker("option", "dateFormat", "mm/dd/yy");
            // Use Ajax to submit form data
            $.ajax({
                type: "POST",
                url: '@Url.Action("Save", "StorageDetail")',
                async: false,
                cache: false,
                data: $('#CheckValid').serialize(),
                success: function (result) {
                    location.href = '@Url.Action("Index", "StorageDetail")'
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert(xhr.status);
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            });
        });
    });
</script>
<div id="breadcrumb">
    <div class="container">
        <div id="con_top">
            <div class="c_container">
                <h3>Chi tiết lưu kho</h3>
            </div>
        </div>
    </div>
</div>
<form class="form-horizontal" role="form" id="CheckValid" style="margin-top: 10px;">
    @if (Model == null)
    {
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Mã phiếu xuất xưởng (*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="ID" name="ID" />
                    <input type="text" class="form-control" id="BillNumber" name="BillNumber" placeholder="Mã phiếu xuất">
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Lệnh kết thúc sản xuất(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("OrderSummaryID", new SelectList(ViewData["OrderSummary"] as IEnumerable<Data.Models.OrderSummary>, "ID", "Code"), "Chọn lệnh kết thúc sản xuất", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày xuất xưởng</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="DateOut" name="DateOut">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Số lượng</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="Quantity" name="Quantity">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
           <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Người duyệt(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("Employee1ID", new SelectList(ViewData["Employee"] as IEnumerable<Data.Models.Employee>, "ID", "Name"), "Chọn người duyệt", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Người giao(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("Employee2ID", new SelectList(ViewData["Employee"] as IEnumerable<Data.Models.Employee>, "ID", "Name"), "Chọn người giao", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Người nhận(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("Employee3ID", new SelectList(ViewData["Employee"] as IEnumerable<Data.Models.Employee>, "ID", "Name"), "Chọn người nhận", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Chuyển đến kho</label>
                <div class="col-sm-8">
                    @Html.DropDownList("WarehouseID", new SelectList(ViewData["Stock"] as IEnumerable<Data.Models.Stock>, "ID", "Name"), "Chọn kho", new { @class = "form-control" })
                </div>
            </div>
        </div>
    }
    else
    {
        <div class="col-sm-6">
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Mã phiếu xuất xưởng (*)</label>
                <div class="col-sm-8">
                    <input type="hidden" id="ID" name="ID" value="@Model.ID" />
                    <input type="text" class="form-control" id="BillNumber" name="BillNumber" placeholder="Mã phiếu xuất" value="@Model.BillNumber">
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Lệnh kết thúc sản xuất(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("OrderSummaryID", new SelectList(ViewData["OrderSummary"] as IEnumerable<Data.Models.OrderSummary>, "ID", "Code",@Model.OrderSummaryID), "Chọn lệnh kết thúc sản xuất", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Ngày xuất xưởng</label>
                <div class="col-sm-8">
                    <div class='input-group date'>
                        <input type="text" class="form-control" id="DateOut" name="DateOut" value="@Convert.ToDateTime(Model.DateOut).ToShortDateString()">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label for="dtEfective" class="col-sm-4 control-label">Số lượng</label>
                <div class="col-sm-8">
                    <div>
                        <input type="text" class="form-control" id="Quantity" name="Quantity" value="@Model.Quantity">
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
           <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Người duyệt(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("Employee1ID", new SelectList(ViewData["Employee"] as IEnumerable<Data.Models.Employee>, "ID", "Name", @Model.Employee1ID), "Chọn người duyệt", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Người giao(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("Employee2ID", new SelectList(ViewData["Employee"] as IEnumerable<Data.Models.Employee>, "ID", "Name",@Model.Employee2ID), "Chọn người giao", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Người nhận(*)</label>
                <div class="col-sm-8">
                    @Html.DropDownList("Employee3ID", new SelectList(ViewData["Employee"] as IEnumerable<Data.Models.Employee>, "ID", "Name",@Model.Employee3ID), "Chọn người nhận", new { @class = "form-control" })
                </div>
            </div>
            <div class="form-group">
                <label for="Code" class="col-sm-4 control-label">Chuyển đến kho</label>
                <div class="col-sm-8">
                    @Html.DropDownList("WarehouseID", new SelectList(ViewData["Stock"] as IEnumerable<Data.Models.Stock>, "ID", "Name",@Model.WarehouseID), "Chọn kho", new { @class = "form-control" })
                </div>
            </div>
        </div>
    }
    <div class="form-group">
        <div class="c_container col-sm-10 col-sm-offset-1" id="processDetail">
            <div class="cleardiv"></div>
            <div class="btn-group">
                <div class="btn-group">
                    <button id="btnSaveSale" type="submit" class="btn btn-defaultxero">Lưu</button>
                </div>
            </div>
            <div class="btn-group">
                <button id="btnCancelSale" type="button" onclick="javascript: location.href = '/StorageDetail';" class="btn btn-defaultxero">Hủy</button>
            </div>
        </div>
    </div>

</form>
<script type="text/javascript">
    $(document).ready(function () {
        $("#OrderID").change(function () {
            if (this.value != "") {
                GetDetail(this.value);
            }
        });
    });
    function GetDetail(element) {
        $.ajax({
            type: "GET",
            url: '@Url.Action("GetDetail", "StorageDetail")',
            async: false,
            cache: false,
            data: { ID: element },
            success: function (result) {
                $('#ProductModelID').prop('disabled', true);
                $('#Quantity').val(result.Quantity);
                $('#TotalCost').val(result.TotalCost);
                $('#ProductModelID').val("@ViewBag.ProductName");
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(xhr.responseText);
                alert(thrownError);
            }
        });
    }
</script>
